package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cch.examSystem.entity.Manager;
import com.cch.examSystem.entity.Scale;
import com.cch.examSystem.entity.ScaleList;

public class scaleListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Date now = new Date();
		SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat time = new SimpleDateFormat("HH:mm");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		List scaleList = new ArrayList();
		ScaleList scale;
		String name = "测试问卷";
		String introduction = "测试介绍";
		String guide = "测试导语";
		String account = "admin";
		for (int i = 0; i < 15; i++) {
			scale = new ScaleList(i, name + i, datetime.format(now), "阶段测试",
					"知识点" + i, "创卷人" + i, 100, "固定问卷", introduction + i, guide
							+ i, datetime.format(now), time.format(now),
					"[{\"question_id\":1,\"score\":1},{\"question_id\":2,\"score\":2}]", "");
			scaleList.add(scale);
		}

		for (int i = 15; i < 30; i++) {
			scale = new ScaleList(i, name + i, datetime.format(now), "知识点练习",
					"知识点" + i, "创卷人" + i, 100, "随机问卷", introduction + i, guide
							+ i, datetime.format(now), time.format(now), "",
					"{\"rank\":1,\"question_number\":10}");
			scaleList.add(scale);
		}
		/* System.out.println(JSON.toJSONString(scaleList)); */
		request.setAttribute("scaleList", scaleList);
		request.getRequestDispatcher("./manager/scaleList.jsp").forward(
				request, response);
		out.flush();
		out.close();
	}
}
